package com.alibaba.citrus.cr.common.enums.ordercenter;

import com.google.gson.annotations.SerializedName;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Getter
public enum OrderChannelEnum {

    COMPANY("100", "分子公司"),
    KA("200", "垂直重客"),
    SPECIAL_CHANNEL("300", "垂直特通"),
    E_COMMERCE("400", "电商"),
    SEPARATE_WAREHOUSE("500", "分仓客户"),
    ;

    @SerializedName(value = "code")
    private final String code;
    @SerializedName(value = "desc")
    private final String desc;

    OrderChannelEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static OrderChannelEnum of(String code) {
        return Arrays.stream(OrderChannelEnum.values()).filter(source -> Objects.equals(code, source.getCode())).findFirst().orElse(null);
    }

    public static String descByCode(String code) {
        OrderChannelEnum orderChannelEnum = of(code);
        return Objects.nonNull(orderChannelEnum) ? orderChannelEnum.getDesc() : "";
    }

    public static List<String> codes() {
        return Arrays.stream(OrderChannelEnum.values()).map(OrderChannelEnum::getCode).collect(Collectors.toList());
    }
}
